home *** CD-ROM | disk | FTP | other *** search
- #!/usr/local/bin/perl
- # program to find the next unallocated IP address in a
- # Class C network by reading the named.hosts file, given the Class C
- # network and the starting address.
- #
- # Eric Murray 1/21/93
- # ericm@microunity.com
-
-
- sub usage {
- print "usage: $0 128.2.30.160\n";
- print "prints next free IP address on the subnet, from named.hosts\n";
- exit;
- }
-
- &usage if ($#ARGV != 0);
- @buf = split('\.',$ARGV[0]);
-
- # network class dependent:
- # this is for Class C.
- $netpart = "$buf[0].$buf[1].$buf[2]";
- $hostpart = "$buf[3]";
-
- open(FH,"named.hosts") || die "can't open named.hosts: $!\n";
- while(<FH>) {
- chop;
- s/;.*$//;
- next if (/^$/);
- next if ($_ !~ /\s+A\s+\d+/); # skip all but A records
- if ($_ =~ /$netpart/) {
- s/^.*A\s+//;
- # it's the same subnet
- $host = $_; $host =~ s/^$netpart\.//;
- next if ($host < $hostpart);
- $nums[$host]++; # mark down.
- }
- }
- foreach ($hostpart .. 255) {
- if (!defined $nums[$_]) { print "$netpart.$_\n"; exit; }
- }
- print "no IP addresses left\n";
-
-